﻿using System;
using System.Net;
using System.Collections.Generic;
using SCG.General;

namespace SCG.SolarVengeanceEngine.StarShips
{
    //ParalyShips
    public class ParalyShip : StarShip
    {
        //constructor
        public ParalyShip(SVGame game, Player owner, int engines, int paralyzeRange, StarSystem origin)
            : base(game, owner, engines, paralyzeRange, origin)
        {
        }

        //ship name
        public override string Name
        {
            get
            {
                return "ParalyShip";
            }
        }

        //description
        public override string Description
        {
            get
            {
                return "ParalyShips paralyze the closest enemy StarShip in their Paralyze Range.  The paralyzed StarShip cannot move, but can otherwise perform actions.";
            }
        }

        //Ship type
        public override StarShipType ShipType
        {
            get
            {
                return StarShipType.ParalyShip;
            }
        }

        //They paralyze the closest enemy StarShip
        protected internal override void PreMoveProcessing()
        {
            double closestDist = Double.MaxValue;
            StarShip closest = null;
            foreach(StarShip ship in Game.StarShips)
                if (!Owner.FriendlyTo(ship.Owner))
                    if (ship.VisibleTo[Owner])
                        if (!_paralyzed.Contains(ship))
                        {
                            double distance = Distance(ship);
                            if (distance <= Value)
                                if (distance < closestDist)
                                {
                                    closestDist = distance;
                                    closest = ship;
                                }
                        }

            //paralize the target
            if (closest != null)
            {
                _paralyzed.Add(closest);
                closest.ProhibitMove = true;
            }
        }

        //Clear the paralyzed list
        protected internal override void CommonPreProcessing()
        {
            _paralyzed.Clear();
        }
        protected internal override void CommonPostProcessing()
        {
            _paralyzed.Clear();
        }

        //render the paralysis range
        public override SCGColor RadiusColor
        {
            get
            {
                return ParalyzeRangeColor;
            }
        }

        //private members
        private static List<StarShip> _paralyzed = new List<StarShip>();
        private static SCGColor ParalyzeRangeColor = new SCGColor(192, 128, 64, 0);
    }
}
